<template>
  <div>
    <van-nav-bar title="超级管理员信息" fixed left-arrow @click-left="$utils.back($route.path)" />
    <div class="has-top">
      <van-form class="mg-25 mt-20" ref="subForm">
        <form-item item-name="管理员信息">
          <van-field
            v-model="info.AdminName"
            name="姓名"
            label="姓名"
            placeholder="姓名"
            :rules="[{ required: true, message: ' ' }]"
          />
          <van-field
            v-model="info.IdnetNo"
            name="证件号码"
            label="证件号码"
            placeholder="证件号码"
            :rules="[{ required: true, message: ' ' }]"
          />
          <van-field
            v-model="info.Mobile"
            name="联系电话"
            label="联系电话"
            placeholder="联系电话"
            :rules="[{ required: true, message: ' ' }]"
          />
          <van-field
            v-model="info.Email"
            name="联系邮箱"
            label="联系邮箱"
            placeholder="联系邮箱"
            :rules="[{ required: true, message: ' ' }]"
          />
        </form-item>
        <div class="btn-box pt-40 pb-60 flex-center">
          <van-button class="br-10 hollow-btn" type="info" @click="handleSubmit()">保存并返回首页</van-button>
        </div>
      </van-form>
    </div>
  </div>
</template>

<script>
import formItem from 'components/formItem'
import { AddMerchantAdminData, GetMerchantApplyData } from 'api/merchantPaper'
export default {
  components: {
    formItem
  },
  data() {
    return {
      info: {
        AccountNo: '',
        AdminName: '',
        IdnetNo: '',
        OpenId: '',
        Mobile: '',
        Email: ''
      },
      accountNo: '',
      done: false
    }
  },
  created() {
    var accountNo = this.$route.query.accountNo
    if (accountNo) {
      this.accountNo = accountNo
      this.GetMerchantApplyData()
    } else {
      this.$toast({
        message: '保存信息前,需要先完成主体信息'
      })
    }
  },
  methods: {
    handleSubmit() {
      this.$refs.subForm.validate().then(() => {
        this.info.AccountNo = this.accountNo
        AddMerchantAdminData(this.info).then(res => {
          if (res) {
            this.$toast.success('操作成功')
            this.$router.replace({
              path: '/merchantPaper/',
              query: { accountNo: this.accountNo }
            })
          }
        })
      })
    },
    //获取信息
    GetMerchantApplyData() {
      GetMerchantApplyData({
        AccountNo: this.accountNo
      }).then(res => {
        if (res) {
          this.info = res.Data.Admin
          this.done = res.Data.InputMain
        }
      })
    },
    onConfirm(value) {
      this.value = value
      this.showPicker = false
    }
  }
}
</script>
<style lang="scss" scoped></style>
